package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackStat;
import com.atguigu.tingshu.vo.album.TrackStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TrackStatMapper extends BaseMapper<TrackStat> {



    @Update("update track_stat set stat_num = stat_num + #{count}, update_time = now() \n" +
            "                  where track_id = #{trackId} and stat_type = #{statType} and is_deleted = 0")
    void updateStat(@Param("trackId") Long trackId, @Param("statType") String statType, @Param("count") Integer count);

    @Select("select\n" +
            "    max(if(stat_type = '0701',stat_num,0)) playStatNum,\n" +
            "    max(if(stat_type = '0702',stat_num,0)) collectStatNum,\n" +
            "    max(if(stat_type = '0703',stat_num,0)) praiseStatNum,\n" +
            "    max(if(stat_type = '0704',stat_num,0)) commentStatNum\n" +
            "from track_stat where track_id = #{trackId} and is_deleted = 0;")
    TrackStatVo getTrackStatVo(Long trackId);
}
